package com.yc.thread.conproExecutor;

import com.yc.thread.conpro.Consumer;

import java.util.Random;
import java.util.concurrent.BlockingQueue;

/**
 *  消费者
 */
public class ConsumerOne implements Runnable{
    private BlockingQueue<DataInfo> queue ;
    private static Random r = new Random();

    public ConsumerOne(BlockingQueue<DataInfo> queue) {
        this.queue = queue;
    }

    @Override
    public void run() {
        while (true) {
            try {
                // 获取数据
                DataInfo take = this.queue.take();
                // 随机休眠0-1000秒，表示数据处理（消费耗时）
                Thread.sleep(r.nextInt(1000));
                System.out.println(Thread.currentThread().getName() + "消费：" + take);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
